#ifndef D_DRAWPROJECT_H
#define D_DRAWPROJECT_H

#include <wx/string.h>
#include <wx/gdicmn.h>
#include "..\ProjectManagement\ProjectManager.h"
#include "..\D-DrawTypes.h"
#include "D-DrawBaseElement.h"

class D_DrawBaseBridgeElement;
class ByteTrain;
class FileManager;
class wxPoint;
class wxClientDC;
class wxDC;
class D_DrawElementFactory;

// 100 dpi document size constants
static const int global_project_width1 = 827;
static const int global_project_height1 = 1169;

class D_DrawProject{
	public:
	D_DrawProject(wxString name, wxString path);
	~D_DrawProject();
	
	void SetProjectName(wxString name);
	wxString GetProjectName();
	void SetProjectPath(wxString path);
	wxString GetProjectPath();
		
	bool SaveToFile();
	bool ReadFromFile();
	
	void Render(wxDC* dc, wxPoint* offset, bool order_by_depth = false);
		
	bool AddElement(wxPoint* position, ElementType type);
	bool AddElement(wxPoint* position, D_DrawBaseElement* element, int& placed_index);
	bool AddElement(D_DrawBaseElement* element);
	bool SelectElement(wxPoint* position);
	SelectionMode UpdateSelectionMode(wxPoint* position);
	bool DeleteElement(wxPoint* position, bool& is_selected);
	bool MoveElement(wxPoint* position);
	bool NodeStart(wxPoint* position);
	bool NodeStep(wxPoint* position, bool& bridge_complete);
	void ClearBridge();
	void UpdateNodes(wxPoint old_position, wxSize old_size, int element_index = -1);
	D_DrawBaseElement* GetSelectedElement();
	void SetSelectionMode(SelectionMode mode);
	void PostMousePosition(wxPoint position);
	bool UpdateSelectedElementWithSelection();
	void SetSelectedBridgeType(ElementType bridge_type);
	
	private:
	bool FeedToByteContainer(unsigned char* data, int length);
	bool ObtainFromByteContainer(unsigned char*& data, int& length);
	void ResetByteContainer();
	void SetZBuffer(D_DrawBaseElement* element, int index);
	bool IsOverlapping(D_DrawBaseElement* element1, D_DrawBaseElement* element2);
	bool IsOverlapping(D_DrawBaseElement* element, wxPoint* position);
	void RenderTargetPointer(D_DrawBaseElement* element, wxDC* dc, wxPoint* offset);
	void RenderNodes(wxDC* dc, wxPoint* offset);
	void RenderSelections(wxDC* dc, wxPoint* offset);
	void updateDepthOfOverlappingElements(D_DrawBaseElement* element, int index);
	wxPoint generateNode(D_DrawBaseElement* element, wxPoint* subject);
	void GenerateSelectionRectangle(wxPoint* position, wxSize* size);
	bool IsBridgeElement(ElementType type);
		
	wxString m_project_name;
	wxString m_project_path;
	static unsigned int m_version;
	D_DrawBaseElement** m_elements;
	D_DrawBaseBridgeElement* m_bridge;
	int m_element_counter;
	ByteTrain* m_byte_container; 
	FileManager* m_file_manager;
	D_DrawElementFactory* m_element_factory;
	int m_selected_element;
	SelectionMode m_selection_mode;
	wxPoint m_mouse_position;
	wxPoint m_moving_offset;
	bool m_selection_at_left_side;
	bool m_selection_at_upper_side;
	ElementType m_selected_bridge_type;
	};

#endif